package response

import "github.com/gin-gonic/gin"

type APIResponse struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

func Success(c *gin.Context, data interface{}, message ...string) {
	msg := "操作成功"
	if len(message) > 0 {
		msg = message[0]
	}
	c.JSON(200, APIResponse{200, msg, data})
}

func Error(c *gin.Context, code int, message string) {
	c.JSON(200, APIResponse{code, message, nil})
}
